import { createRouter, createWebHashHistory } from 'vue-router';

import Layout from '@/layout/index.vue';

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index.vue'),
  },
  {
    path: '/404',
    component: () => import('@/components/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/components/error-page//401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      { 
        path: "dashboard",
        name: 'dashboard',
        component: () => import('@/components/HelloWorld.vue'),
      }
    ]
  },
  { path: '/:pathMatch(.*)*', name: 'NotFound', component: () => import('@/components/error-page/404.vue') }
]


const router = createRouter({
  history: createWebHashHistory(), // hash模式：createWebHashHistory，history模式：createWebHistory
  routes: constantRoutes
})

export const resetRouter = () => {
  const newRouter = createRouter({routes: [], history: createWebHashHistory()});
  router.matcher = newRouter.matcher // reset router
}

export default router;